using System;
using eShop.Business;

public partial class recover : SitePublicBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void btnRecoverMyPassword_Click(object sender, EventArgs e)
    {
        try
        {
            if (IsValid)
            {
                string LoginEmailAddress = tbxEmailAddress.Text.Trim();
                if (UserManager.IsUserExists(LoginEmailAddress))
                {
                    eShop.Model.User customerUser = UserManager.GetUserByUserName(LoginEmailAddress);
                    if (customerUser != null)
                    {
                        if (new Email().SendPasswordRecoverEmail(customerUser))
                        {
                            uccResponseMessage.SetSuccessMessage("An email with your password has been sent to " + customerUser.Profile.EmailAddress + ". <a href="+ CustomSiteMap.Login+"> click here to login</a>");
                            uccResponseMessage.Visible = true;
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    uccResponseMessage.SetFailMessage("Member not found with this email address.");
                    uccResponseMessage.Visible = true;
                }
            }
        }
        catch
        {
            uccResponseMessage.SetFailMessage("Password recovery failed. Please try later.");
            uccResponseMessage.Visible = true;
        }
    }
}
